package com.apartmentManage.controller.interceptor;


import com.apartmentManage.until.LoginResponse;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor  extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String url=request.getRequestURI();
        if (url.indexOf("/login")>=0 || url.indexOf("/admin")>=0
                || url.contains("/css/")
                || url.contains("/js/") || url.contains("/images/")
                || url.indexOf("/img")>=0){
            return true;
        }
        if (LoginResponse.map.get("ADMIN")!=null)
               return true;
        request.getRequestDispatcher("/login").forward(request,response);
        return false;
    }
}
